﻿using System;
using SharpSqlAnalyzer.nodes;
using SharpSqlAnalyzer.nodes.hive;

namespace SharpSqlAnalyzer.stmt.hive
{
	// Token: 0x020001BE RID: 446
	public class THiveFromQuery : TCustomSqlStatement
	{
		// Token: 0x170002B5 RID: 693
		// (get) Token: 0x06000ED8 RID: 3800 RVA: 0x0030A95C File Offset: 0x00308B5C
		// (set) Token: 0x06000ED9 RID: 3801 RVA: 0x0030A977 File Offset: 0x00308B77
		public virtual TStatementList HiveBodyList
		{
			get
			{
				if (this.hiveBodyList == null)
				{
					this.hiveBodyList = new TStatementList();
				}
				return this.hiveBodyList;
			}
			set
			{
				this.hiveBodyList = value;
			}
		}

		// Token: 0x06000EDA RID: 3802 RVA: 0x0030A980 File Offset: 0x00308B80
		public THiveFromQuery(EDbVendor dbvendor) : base(dbvendor)
		{
			this.sqlstatementtype = ESqlStatementType.ssthiveFromQuery;
		}

		// Token: 0x06000EDB RID: 3803 RVA: 0x0030A994 File Offset: 0x00308B94
		public override int doParseStatement(TCustomSqlStatement psql)
		{
			if (this.rootNode == null)
			{
				return -1;
			}
			base.doParseStatement(psql);
			THiveFromQuerySqlNode thiveFromQuerySqlNode = (THiveFromQuerySqlNode)this.rootNode;
			for (int i = 0; i < thiveFromQuerySqlNode.FromTableList.size(); i++)
			{
				TFromTable fromTable = thiveFromQuerySqlNode.FromTableList.getFromTable(i);
				TJoin tjoin;
				if (fromTable.FromtableType != ETableSource.join)
				{
					tjoin = new TJoin();
					tjoin.Table = this.analyzeFromTable(fromTable, new bool?(true));
					tjoin.startToken = tjoin.Table.startToken;
					tjoin.endToken = tjoin.Table.endToken;
					tjoin.GSharpSqlParser = this.GSharpSqlParser;
				}
				else
				{
					tjoin = this.analyzeJoin(fromTable.JoinExpr, null, new bool?(true));
					tjoin.doParse(this, ESqlClause.join);
				}
				this.joins.addJoin(tjoin);
			}
			if (thiveFromQuerySqlNode.HiveBodyList != null)
			{
				for (int j = 0; j < thiveFromQuerySqlNode.HiveBodyList.Count; j++)
				{
					TParseTreeNode tparseTreeNode = thiveFromQuerySqlNode.HiveBodyList[j];
					int nodeType = tparseTreeNode.NodeType;
					if (nodeType != 100)
					{
						if (nodeType == 103)
						{
							TInsertSqlStatement tinsertSqlStatement = new TInsertSqlStatement(EDbVendor.dbvhive);
							tinsertSqlStatement.rootNode = tparseTreeNode;
							tinsertSqlStatement.doParseStatement(this);
							this.HiveBodyList.add(tinsertSqlStatement);
						}
					}
					else
					{
						TSelectSqlStatement tselectSqlStatement = new TSelectSqlStatement(EDbVendor.dbvhive);
						tselectSqlStatement.rootNode = tparseTreeNode;
						tselectSqlStatement.doParseStatement(this);
						this.HiveBodyList.add(tselectSqlStatement);
					}
				}
			}
			return 0;
		}

		// Token: 0x06000EDC RID: 3804 RVA: 0x0030AB05 File Offset: 0x00308D05
		public override void accept(TParseTreeVisitor v)
		{
			v.preVisit(this);
			v.postVisit(this);
		}

		// Token: 0x06000EDD RID: 3805 RVA: 0x0030AB15 File Offset: 0x00308D15
		public override void acceptChildren(TParseTreeVisitor v)
		{
			v.preVisit(this);
			if (this.hiveBodyList != null)
			{
				this.hiveBodyList.accept(v);
			}
			v.postVisit(this);
		}

		// Token: 0x04001347 RID: 4935
		private TStatementList hiveBodyList;
	}
}
